package com.googlecode.stemwijzer.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.stemwijzer.client.presenter.NotificationPresenter;

public class NotificationView extends Composite implements
		NotificationPresenter.Display {

	private static NotificationViewUiBinder uiBinder = GWT
			.create(NotificationViewUiBinder.class);

	interface NotificationViewUiBinder extends
			UiBinder<HTMLPanel, NotificationView> {
	}

	@UiField
	Label notification;

	@UiField
	Label error;

	public NotificationView() {
		initWidget(uiBinder.createAndBindUi(this));

		notification.setVisible(false);
		error.setVisible(false);
	}

	@Override
	public Widget asWidget() {
		return this;
	}

	@Override
	public void startProcessing() {
	}

	@Override
	public void stopProcessing() {
	}

	@Override
	public void showMessage(String message) {
		notification.setVisible(true);
		notification.setText(message);

		Timer timer = new Timer() {
			public void run() {
				notification.setVisible(false);
			}
		};
		timer.schedule(2000);
	}

	@Override
	public void showError(String errorMsg) {
		error.setVisible(true);
		error.setText(errorMsg);

		Timer timer = new Timer() {
			public void run() {
				error.setVisible(false);
			}
		};
		timer.schedule(2000);
	}
}
